import openai
import requests

from setting import url_trans, headers

def init():
    openai.organization = "org-4XLXWWwLTc8YdcOalDGPNcJx"
    openai.api_key = "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"
    #model_list = openai.Model.list()
    #print(type(model_list))
    global headers
    headers = {
        "Accept": "*/*",
        "Content-Type": "multipart/form-data",
        "Authorization": "Bearer {0}".format(openai.api_key),
        "Accept-Encoding": "gzip, deflate",
        #"Host": "api.openai.com",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
        "Referrer Policy": "strict-origin-when-cross-origin",
        "Method": "POST"
    }


def trans():
    post_content = {
        "file": "d:\\bird01.mp3",
        "model": "whisper-1"
    }
    print(headers)
    myfile = requests.post(headers=headers, url=url_trans, data=post_content)

    open("d:\\test.txt", 'wb').write(myfile.content)


def trans2():
    audio_file = open("D:\\MyCode\\py-learning\\ai\\chatgpt-voice\\test.mp3", "rb")
    transcript = openai.Audio.transcribe("whisper-1", audio_file)
    print(transcript.text)
    return transcript.text


def trans3(file):
    audio_file = open(file, "rb")
    transcript = openai.Audio.transcribe("whisper-1", audio_file)
    print(transcript.text)
    return transcript.text


